#include "process.h"
#include <string.h>
#include <unistd.h>

#define NUM 101
#define STYLE '='

void FlushProcess(double total, double current){
    char buffer[NUM]; 
    const char* lable = "|/\\";
    size_t len = strlen(lable);
    memset(buffer, 0, sizeof(buffer));
    double rate = current / total;
    
    int num = (int) (current * 100 / total);
    
    for(int i=0;i<num;i++){
        buffer[i] = STYLE;
    }

    static int cnt = 0;
    cnt %= len;
    printf("[%-100s][%.2lf%%][%c]\r", buffer, rate*100, lable[cnt]);
    cnt++;
    fflush(stdout);
}


//void process_v1(){ 
   //char buffer[NUM]; 
    // const char* lable = "|/\\";
    //size_t len = strlen(lable);
    //memset(buffer, 0, sizeof(buffer));
    //while(cnt <= 100){
        //printf("[%-100s][%d%%][%c]\r", buffer, cnt, lable[cnt%len]);
        //fflush(stdout);
        //buffer[cnt] = STYLE;
        //usleep(50000);
    //}
    //printf("\n");
//}
